import Vue from 'vue'
import App from './App.vue'
import router from './router';
import ElementUI from 'element-ui';
import store from './store';
import 'element-ui/lib/theme-chalk/index.css';
import './api/mock'
import Cookie from 'js-cookie'
Vue.config.productionTip = false
Vue.use(ElementUI);
 
router.beforeEach((to,from,next)=>{
  const token =Cookie.get('token')
  if(!token && to.name!=='login'){
  next('/login')
  }else if ( token && to.name  ==='login'   ){
    next('/home')
  }else{
    next()
  }
})
  



new Vue({
  router,
  store,
  created(){
    store.commit('addMenu',router)
  },
  render: h => h(App),
}).$mount('#app')
